const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: {},
        bususer: {},
        files: [],
        files1: [],
        checkid:"",

        checkForm: {
            checkTime: "",
            checkUserName: "",
            checkUserId: "",
            tailCarId: "",
            rectItem: "",
            rectTotal: "",
            isRect: "",
            isLight: "",
            isTurnto: "",
            isRun: "",
            isTyre: "",
            isSafeDoor: "",
            isSwitch: "",
            isExit: "",
            isFire: "",
            isSafeHammer: "",
            isSafeBelt: "",
            isWarnTriangle: "",
            isGPS: "",
            isDriveSus: "",
            isTanksTires: "",
            isFireEqu: "",
            isDangerMark: "",
            isElectDevice: "",
            isSparkDevice: "",
            isFlameArres: "",
            isValve: "",
            isTankInte: "",
            isFastenParts: "",
            isProtectArti: "",
            onePicUrlId: "",
            twoPicUrlId: "",
            threePicUrlId: "",
            fourPicUrlId: "",
            fivePicUrlId: "",
            sixPicUrlId: "",
            sevenPicUrlId: "",
            eightPicUrlId: "",
            ninePicUrlId: "",
            driverUser: {
                id: ""
            },
            car: {
                id: ""
            }

        },
        checkImages:[],
        zhenggaiImages:[],
        listresult:[]
    },
    imageError: function (e) {
        console.log('image3发生error事件，携带值为', e.detail.errMsg)
    },


    imagetap: function (e) {
        console.log(e);
        wx.previewImage({
          current: e.currentTarget.dataset.imageurl, // 当前显示图片的http链接
          urls: [e.currentTarget.dataset.imageurl] // 需要预览的图片http链接列表
        })
    },
    loadcheckiddata: function (id) {
        wx.showLoading({
            title: '正在加载数据'
        })
        var that = this
        wx.request({
            method: 'POST',
            url: app.globalData.serverPath + "api/bs-car-safe-checks-info",
            header: {
                'Authorization': app.globalData.token,
                'content-type': 'application/x-www-form-urlencoded'
            },
            data: {
                check_id: this.data.checkid
            },
            success: function (res) {
                wx.hideLoading();
                console.log(res)

                that.setData({
                    checkForm: res.data.bsCarSafeCheck,
                    zhenggaiImages:res.data,
                    list:res.data.item0,
                    listresult:res.data.item1
                })
                var images=[];
                if (that.data.checkForm.onePicUrlId && that.data.checkForm.onePicUrlId.length>0){
                    images.push(that.data.checkForm.onePicUrlId);
                }
                if (that.data.checkForm.twoPicUrlId && that.data.checkForm.twoPicUrlId.length > 0) {
                    images.push(that.data.checkForm.twoPicUrlId);
                }
                if (that.data.checkForm.threePicUrlId && that.data.checkForm.threePicUrlId.length > 0) {
                    images.push(that.data.checkForm.threePicUrlId);
                }
                if (that.data.checkForm.fourPicUrlId && that.data.checkForm.fourPicUrlId.length > 0) {
                    images.push(that.data.checkForm.fourPicUrlId);
                }
                if (that.data.checkForm.fivePicUrlId && that.data.checkForm.fivePicUrlId.length > 0) {
                    images.push(that.data.checkForm.fivePicUrlId);
                }
                if (that.data.checkForm.sixPicUrlId && that.data.checkForm.sixPicUrlId.length > 0) {
                    images.push(that.data.checkForm.sixPicUrlId);
                }
                if (that.data.checkForm.sevenPicUrlId && that.data.checkForm.sevenPicUrlId.length > 0) {
                    images.push(that.data.checkForm.sevenPicUrlId);
                }
                if (that.data.checkForm.eightPicUrlId && that.data.checkForm.eightPicUrlId.length > 0) {
                    images.push(that.data.checkForm.eightPicUrlId);
                }
                if (that.data.checkForm.ninePicUrlId && that.data.checkForm.ninePicUrlId.length > 0) {
                    images.push(that.data.checkForm.ninePicUrlId);
                }
                console.log(images);
                images = images.concat(that.data.list).concat(that.data.listresult);
                that.setData({
                    checkImages:images
                })

            }
        })
    },
    confirmcheck:function(){
        wx.showLoading({
            title: '正在提交数据',
        })
        wx.request({
            method: 'POST',
            url: app.globalData.serverPath + "api/confirm-bs-car-safe-checks",
            header: {
                'Authorization': app.globalData.token,
                'content-type': 'application/x-www-form-urlencoded'
            },
            data: {
                check_id: this.data.checkid
            },
            success:function(res){
                if(res.statusCode==200){
                    wx.navigateBack();
                }
            },
            complete:function(){
                wx.hideLoading();
            }

        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var id=options.checkid;
        this.setData({checkid:options.checkid});
        

        if (app.globalData.userInfo && app.globalData.bususer) {
            this.setData({
                userInfo: app.globalData.userInfo,
                hasUserInfo: true,
                bususer: app.globalData.bususer
            })
        } else {
            // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
            // 所以此处加入 callback 以防止这种情况
            app.userInfoReadyCallback = res => {
                this.setData({
                    userInfo: app.globalData.userInfo,
                    hasUserInfo: true,
                    bususer: app.globalData.bususer
                })
                this.loadcheckiddata(id)
            }
        }
    },
    zhenggaiResult:function(e){
        wx.navigateTo({
            url: '../zhenggai-result/zhenggai-result?checkid='+this.data.checkid
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
      this.loadcheckiddata(this.data.checkid);
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})